/*
 * Copyright 2007 Jeffrey Palm
 */

import java.io.*;
import java.net.*;

import org.farng.mp3.*;
import org.farng.mp3.id3.*;

abstract class AbstractFinderIPodWithLogin extends AbstractFinderIPod {

 protected String username;
  protected String password;

  public AbstractFinderIPodWithLogin(String username,String password) {
    this.username = username;
    this.password = password;
  }

  public AbstractFinderIPodWithLogin() {
  }

  protected abstract void findRestRest(IPod ipod, Progress p) throws Exception;

  protected final void findRest(IPod ipod, Progress p) throws Exception {
    username = Config.getInstance().get(getClass().getName()+":"+Props.USERNAME);
    password = Config.getInstance().get(getClass().getName()+":"+Props.PASSWORD);
    LoginInfoFrame login = null;
    boolean save = false;
    do {
      if (login == null) login = new LoginInfoFrame(username,password);
      login.show();
      if (login.isCancelled()) return;
      username = login.getUsername();
      password = login.getPassword();
      save = login.isChecked();
    } while (Util.isEmpty(username) || Util.isEmpty(password));
    if (save) {
      Config.getInstance().set(getClass().getName()+":"+Props.USERNAME,username);
      Config.getInstance().set(getClass().getName()+":"+Props.PASSWORD,password);
    }
    findRestRest(ipod,p);
  }

}